package org.springframework.security.authentication;

import org.springframework.security.core.Authentication;

/**
 * @author Dillon
 * @date 2024/7/14
 * @slogan 致敬大师 致敬未来的你
 * @desc 认证信任解析器实现类
 */
public class AuthenticationTrustResolverImpl implements AuthenticationTrustResolver {

	private Class<? extends Authentication> anonymousClass = AnonymousAuthenticationToken.class;

	private Class<? extends Authentication> rememberMeClass = RememberMeAuthenticationToken.class;

	Class<? extends Authentication> getAnonymousClass() {
		return this.anonymousClass;
	}

	Class<? extends Authentication> getRememberMeClass() {
		return this.rememberMeClass;
	}

	/**
	 * 判断当前认证对象是否未匿名认证对象
	 *
	 * @param authentication 认证对象
	 * @return 是否为匿名认证
	 */
	@Override
	public boolean isAnonymous(Authentication authentication) {
		if ((this.anonymousClass == null) || (authentication == null)) {
			return false;
		}
		return this.anonymousClass.isAssignableFrom(authentication.getClass());
	}

	/**
	 * 判断当前认证是否为记住我认证
	 *
	 * @param authentication 认证对象
	 * @return 是否为记住我认证
	 */
	@Override
	public boolean isRememberMe(Authentication authentication) {
		if ((this.rememberMeClass == null) || (authentication == null)) {
			return false;
		}
		return this.rememberMeClass.isAssignableFrom(authentication.getClass());
	}

	public void setAnonymousClass(Class<? extends Authentication> anonymousClass) {
		this.anonymousClass = anonymousClass;
	}

	public void setRememberMeClass(Class<? extends Authentication> rememberMeClass) {
		this.rememberMeClass = rememberMeClass;
	}

}
